package com.itboye.mengwu.data.repository;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.utils.BaseErrorListener;
import com.itboye.core.utils.BaseSuccessReqListener;
import com.itboye.core.utils.ByJsonRequest.Builder;
import com.itboye.mengwu.data.interfaces.IBaby;
import com.itboye.mengwu.data.model.BabyBean;
import com.itboye.mengwu.ui.shop.GoodsDetailsRootBean;

public class BabyRepository extends BaseNetRepository implements
		IBaby<BabyBean> {
	String api = "100";
	public static final String BABYTIANJIANG = "BY_Baby_add";
	public static final String BABYALL = "BY_Baby_query";
	public static final String BABYDETIAL = "BY_Baby_detail";
	public static final String BABYXILIAN = "BY_Baby_update";
	public static final String BABYDELETE = "BY_Baby_delete";

	public BabyRepository(ICompleteListener listener) {
		// TODO Auto-generated constructor stub
		super(listener);
	}

	@Override
	public void add(BabyBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<ArrayList<BabyBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", model.getUid());
		params.put("name", model.getBaby_name());
		params.put("sex", model.getSex());
		params.put("birthday", model.getBirthday());
		params.put("is_default", model.getIs_default());
		params.put("head", model.getHead());

		(new Builder<ArrayList<BabyBean>>())
				.setTypeVerParamsAndReturnClass(BABYTIANJIANG, apiVer, params,
						type)
				.requestListener(
						new BaseSuccessReqListener<ArrayList<BabyBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void delete(BabyBean model) {
		// TODO Auto-generated method stub
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", model.getUid());
		params.put("id", model.getId());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(BABYDELETE, apiVer, params,
						String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void update(BabyBean model) {
		// TODO Auto-generated method stub
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", model.getUid());
		params.put("name", model.getBaby_name());
		params.put("sex", model.getSex());
		params.put("birthday", model.getBirthday());
		params.put("is_default", model.getIs_default());
		params.put("head", model.getHead());
		params.put("id", model.getId());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(BABYXILIAN, apiVer, params,
						String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getInfo(BabyBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<BabyBean> query(BabyBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void BabyDetial(String uid, String id) {
		// TODO Auto-generated method stub
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", uid);
		params.put("id", id);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(BABYDETIAL, apiVer, params,
						String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void BabyAll(String uid) {
		Type type = new TypeToken<ArrayList<BabyBean>>() {
		}.getType();
		String apiVer = api;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("uid", uid);

		(new Builder<ArrayList<BabyBean>>())
				.setTypeVerParamsAndReturnClass(BABYALL, apiVer, params, type)
				.requestListener(
						new BaseSuccessReqListener<ArrayList<BabyBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
